package top.lfyao.designpattern.details.prototype;


/**
 * 原型模式客户端 演示深度拷贝和浅度拷贝
 * <p>
 * 考虑优化此处的重复代码
 */
public class PrototypeClient {
    // 浅拷贝
    public static void shallowCopy() throws CloneNotSupportedException {
        Resume resume = new Resume();
        resume.setName("王海");
        resume.setGender("女");
        resume.setAge(18);
        resume.setWorkExperience(new WorkExperience("1994-0230", "海水有限公司"));

        Resume cloneA = (Resume) resume.clone();
        cloneA.getWorkExperience().setWorkeDate("2000-0230");
        cloneA.setGender("男");
        Resume cloneB = (Resume) resume.clone();
        cloneB.getWorkExperience().setWorkCompany("大海公司");
        System.out.println(">>>>>>浅度拷贝:");
        resume.display();
        cloneA.display();
        cloneB.display();

    }
    // 深拷贝
    public static void deepCopy() throws Exception {
        Resume resume = new Resume();
        resume.setName("王海");
        resume.setGender("女");
        resume.setAge(18);
        resume.setWorkExperience(new WorkExperience("1994-0230", "海水有限公司"));

        Resume cloneA = (Resume) resume.deepClone();
        cloneA.getWorkExperience().setWorkeDate("2000-0230");
        cloneA.setGender("男");
        Resume cloneB = (Resume) resume.deepClone();
        cloneB.getWorkExperience().setWorkCompany("大海公司");
        Resume cloneC = (Resume) resume.deepClone();
        System.out.println(">>>>>>深度拷贝:");
        resume.display();
        cloneA.display();
        cloneB.display();
        cloneC.display();
    }

    
    public static void main(String[] args) throws Exception {
        shallowCopy();
        deepCopy();
    }
}
